package javavis.jip3d.functions;

import javavis.base.Function3DGroup;
import javavis.base.JIPException;
import javavis.base.ParamType;
import javavis.jip3d.gui.Function3D;
import javavis.jip3d.gui.FunctionParam;
import javavis.jip3d.gui.ScreenData;
import javavis.jip3d.gui.ScreenOptions;
import javavis.jip3d.gui.dataobjects.PointSet3D;
import javavis.jip3d.gui.dataobjects.SR4000Set3D;
import javavis.jip3d.gui.dataobjects.Trajectory;

/**
 * 
 * @author dviejo
 *
 * This class is used to automate the image extraction process for SR4K 3D datasets
 */
public class FSR4kImageProcess extends Function3D {

	public FSR4kImageProcess()
	{
		name = "FSR4kImageProcess";
		this.allowed_input = ScreenOptions.tTRAJ3D;
		this.group = Function3DGroup.Image;
		
		FunctionParam p1 = new FunctionParam("Output", ParamType.DIR); 
		FunctionParam p4 = new FunctionParam("SeqName", ParamType.STRING); 
		
		FunctionParam p2 = new FunctionParam("Format", ParamType.LIST);
		String []list = new String[3];
		list[0] = "PNG/PGM";
		list[1] = "JPG";
		list[2] = "JIP";
		p2.setValue(list);
		
		FunctionParam p3 = new FunctionParam("Type", ParamType.LIST);
		String []type = new String[2];
		type[0] = "Intensity";
		type[1] = "Confidence";
		p3.setValue(type);
		
		addParam(p1);
		addParam(p4);
		addParam(p3);
		addParam(p2);

	}
	
	
	@Override
	public void proccessData(ScreenData scr_data) throws JIPException {
		String outputPath = paramValueString("Output");
		String name = paramValueString("SeqName");
		String format = paramValueString("Format");
		String type = paramValueString("Type");
		
		Function3D ftrans;
		int total, cont;
		String fileName;
		SR4000Set3D sr4kset;
		String outputName;
		
		if(type.compareTo("Intensity")==0)
		{
			ftrans = new FSR4kIntensity();
		}
		else ftrans = new FSR4kConfidence();
		
		ftrans.setParamValue("format", format);
System.out.println("Formato elegido: "+format);
		
		Trajectory traj = (Trajectory)scr_data;
		total = traj.files.size();
		String path = traj.path;
		for(cont=0;cont<total;cont++)
		{
			fileName = traj.files.get(cont);
			sr4kset = new SR4000Set3D(new ScreenOptions());
			sr4kset.name = fileName;
			sr4kset.readData(fileName, path);
			
			outputName = outputPath + "/" + name;
			if(cont<10)
				outputName += "00"+cont;
			else if(cont<100)
				outputName += "0"+cont;
			else
				outputName += cont;

			ftrans.setParamValue("Output", outputName);
			ftrans.proccessData(sr4kset);
		}

	}

}
